home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / STRCHR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  526 b   |  23 lines

  1. /* strchr.c  From TC Bible page 275  Use strchr to find the first
  2. occurence of a particular character in a given string. */
  3.  
  4. #include <stdio.h>
  5. #include <conio.h>
  6. #include <string.h>
  7. main()
  8. {
  9.     int c;
  10.     char buf[80], *result;
  11.     printf("Enter a string: ");
  12.     gets(buf);
  13.     printf("Enter a character to be located (first occurrence):");
  14.     c = getche();
  15.     if ((result = strchr(buf, c)) == NULL)
  16.     {
  17.         printf("\n'%c' <-- not in \"%s\"\n", c, buf);
  18.     }
  19.     else
  20.     {
  21.         printf("\n'%c' first occurs at: %s\n",c, result);
  22.     }
  23. }